<!--
 * @Author: your name
 * @Date: 2021-06-04 09:34:49
 * @LastEditTime: 2021-06-04 11:40:02
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tourismpc\src\views\community\components\medical\detail\index.vue
-->
<template>
  <div class="detail">
    <div>
      <h3 style="color: #333333; text-align: center">{{detailData.medicalName}}</h3>
      <div class="heder">
        <div class="nameImg">
          <div class="userAvatar">
            <img style="width: 100%; height: 100%" :src="detailData.medicalInfoUrl" alt />
          </div>
          <div class="name">{{detailData.medicalName}}</div>
        </div>
        <div>{{detailData.medicalTimeStr}}</div>
      </div>
      <el-divider></el-divider>
    </div>
    <div>
      <div class="text">
        <div style="text-indent: 2em">{{detailData.medicalInfo1}}</div>
        <div class="decImg">
          <img :src="detailData.medicalInfoUrl" alt />
        </div>
        <div style="text-indent: 2em">{{detailData.medicalInfo2}}</div>
      </div>
      <br />
      <div class="mapDiv">
        <span class="titleText">定位导航</span>
        <el-input class="searchInput" v-model="address" placeholder="请输入地址">
          <el-button @click="onSearch" slot="append" icon="el-icon-search"></el-button>
        </el-input>
        <div id="educationMapContainer" style="width: 1220px; height: 614px; margin-top: 20px"></div>
      </div>
      <div
        class="nextPage"
        @click="getDetail(detailData.nextMedicalId)"
      >下一页：{{detailData.nextMedicalName}}</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      geocoder: null,
      marker: null,
      api: this.$apiPath.getMedicalInfo,
      detailData: {},
      address: "",
      coordinate: {
        longitude: 104.07,
        latitude: 30.67,
      },
    };
  },
  mounted() {
    let that = this;
    that.getDetail();
  },
  methods: {
    initMap() {
      //步骤：定义map变量 调用 qq.maps.Map() 构造函数   获取地图显示容器
      //设置地图中心点
      let that = this;
      var myLatlng = new qq.maps.LatLng(
        this.coordinate.latitude,
        this.coordinate.longitude
      );
      //定义工厂模式函数
      var myOptions = {
        zoom: 15, //设置地图缩放级别
        center: myLatlng, //设置中心点样式
        mapTypeId: qq.maps.MapTypeId.ROADMAP, //设置地图样式详情参见MapType
        zoomControl: false, //隐藏缩放控件
        panControl: false, //隐藏平移控件
      };
      //获取dom元素添加地图信息
      var map = new qq.maps.Map(
        document.getElementById("educationMapContainer"),
        myOptions
      );
      that.marker = new qq.maps.Marker({
        map,
        position: myLatlng,
      });
      this.geocoder = new qq.maps.Geocoder({
        complete(result) {
          map.setCenter(result.detail.location);
          if (that.marker) {
            that.marker.setMap(null);
          }
          that.marker = new qq.maps.Marker({
            map,
            position: result.detail.location,
          });
        },
      });
    },
    onSearch() {
      this.geocoder.getLocation(this.address);
    },
    getDetail(medicalId) {
      let that = this;
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
      this.$http
        .fetch(
          `${this.api}?medicalId=${
            medicalId ? medicalId : this.$route.query.medicalId
          }`,
          {
            method: "get",
          }
        )
        .then((res) => {
          if (res.code === 200) {
            this.detailData = res.data;
            this.coordinate.latitude = res.data.latitude;
            this.coordinate.longitude = res.data.longitude;
            that.initMap();
          }
        })
        .catch((err) => {
          return Promise.reject(err);
        });
    },
  },
};
</script>

<style lang="less">
.detail {
  width: 1220px;
  margin: 0 auto;
  .heder {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    width: 350px;
    margin: 0 auto;
    margin-top: 18px;
    .userAvatar {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      overflow: hidden;
    }
    .nameImg {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .name {
      // margin-left: -20px;
    }
  }
  .text {
    color: #666666;
    .decImg {
      width: 700px;
      height: 450px;
      margin: 48px auto;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .mapDiv {
    position: relative;
    .searchInput {
      position: absolute;
      z-index: 999;
      top: 60px;
      left: 22px;
    }
  }
  .titleText {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #333333;
    line-height: 8px;
  }
  .el-input-group {
    width: 400px;
    .el-input-group__append {
      background-color: #cf975a;
      .el-icon-search {
        color: #fff;
      }
    }
  }
  .nextPage {
    margin: 0 auto;
    color: #666666;
    text-align: center;
    margin-top: 39px;
    margin-bottom: 50px;
    cursor: pointer;
  }
}
</style>